﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using KPIS.GERP.GHRMS.BLL;
using KPIS.GERP.GHRMS.IBLL;
using KPIS.GERP.GHRMS.MODEL;
using Telerik.Web.UI;
using System.Globalization;

namespace KPIS.GERP.GHRMS.APP.App_UI.Forms
{
    public partial class PR_BudgetManageSummary : System.Web.UI.Page
    {
        private BudgetManagementTestBLL BLL = new BudgetManagementTestBLL();
        private IEmployeeTypeBLL etBLL = new EmployeeTypeBLL();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                bindEmpType();
                ListYear(2500, 2600);
            }
        }
        private void LoadDataGrid()
        {
            int nYear = cbYear.SelectedValue.Length > 0 ? Convert.ToInt32(cbYear.SelectedValue) : 0;
            int nEmpType = cmbEmployeeType.SelectedValue.Length > 0 ? Convert.ToInt32(cmbEmployeeType.SelectedValue) : 0;
            int nPeriod = Convert.ToInt32(radPromotion.SelectedValue);

            try
            {
                RadGrid2.DataSource = BLL.SelectManageSummary(nEmpType, nYear, nPeriod);
                RadGrid2.DataBind();
            }
            catch
            {

            }
        }
        private void bindEmpType()
        {
            IList<EmployeeTypeInfo> infoList = etBLL.ListEmployeeTypes();
            cmbEmployeeType.DataSource = infoList;
            cmbEmployeeType.DataBind();
        }
        public void ListYear(int MinYear, int MaxYear)
        {
            DataTable dt = new DataTable();
            DataColumn dc = dt.Columns.Add("Name");

            for (int i = MinYear; i <= MaxYear; i++)
            {
                dt.Rows.Add(Convert.ToString(i));
            }
            cbYear.DataSource = dt;
            cbYear.DataBind();
        }
        protected void RadGrid2_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
        {
            if (e.CommandName == "InitInsert")
            {
                int nYear = cbYear.SelectedValue.Length > 0 ? Convert.ToInt32(cbYear.SelectedValue) : 0;
                int nEmpType = cmbEmployeeType.SelectedValue.Length > 0 ? Convert.ToInt32(cmbEmployeeType.SelectedValue) : 0;
                int nPeriod = Convert.ToInt32(radPromotion.SelectedValue);

                Session["PrmSeq"] = BLL.GetPrmPromotionSeq(nEmpType, nYear, nPeriod);
            }
        }
        protected void cmbEmployeeType_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)
        {
            LoadDataGrid();
        }

        protected void cbYear_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)
        {
            LoadDataGrid();
        }

        protected void radPromotion_SelectedIndexChanged(object sender, EventArgs e)
        {
            LoadDataGrid();
        }
    }
}
